<?php

namespace Home\Controller;

use Home\Org\Util\Sqlserver;

class OutsideQueryController extends HomeController {

    public function index(){
        exit();
    }

    public function day20180807(){
        $this->display();
    }

    public function day20180807result(){

        import("@.ORG.Util.Sqlserver");
        $sqlserver  = new Sqlserver();

        $FromDate = $_REQUEST['FromDate'];
        $ToDate = $_REQUEST['ToDate'];

        $sqlquery="select
t0.Cardcode,
dbo.BPcontact(t0.Cardcode,'CardName') CardName,
SUM(Quantity) SUMQTY,
SUM(linetotal) SUMPRICE
from ax_reportx T0 left join oitm T1 ON T0.Itemcode=T1.itemcode
where T0.cardcode  in  ('C20086','C20123','C20054','C20093','C20122') 
and t0.docdate>=CONVERT(datetime, '".$FromDate."') and t0.docdate<=CONVERT(datetime, '".$ToDate."')  group by  t0.CardCode";

        $data = $sqlserver->query($sqlquery);

        $sqlserver->close();

        $this->assign("data",$data);
        $this->assign("FromDate",$FromDate);
        $this->assign("ToDate",$ToDate);
        $this->display();

    }

    public function day20180807pop(){

        $code = $_REQUEST['code'];

        $FromDate = $_REQUEST['f'];
        $ToDate = $_REQUEST['t'];

        import("@.ORG.Util.Sqlserver");
        $sqlserver  = new Sqlserver();

        $sqlquery="select
T0.itemcode,
T1.itemname,
T0.pmanager,
SUM(Quantity) SUMQTY,
SUM(linetotal) SUMPRICE
from ax_reportx T0 left join oitm T1 ON T0.Itemcode=T1.itemcode
where T0.cardcode ='".$code."'
and t0.docdate>=CONVERT(datetime, '".$FromDate."') and t0.docdate<=CONVERT(datetime, '".$ToDate."')
group by T0.itemcode, T1.itemname,T0.pmanager";

        $data = $sqlserver->query($sqlquery);

        $sqlserver->close();

        $this->assign("data",$data);
        $this->display();

    }

}